package kuzmenkov.applet;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
 * The class translates mouse events of an originator to another one
 * @author Michael Kuzmenkov
 *
 */
public class TransMouseListener implements MouseListener {
	
	/**
	 * The source of the mouse events
	 */
	private Object source;
	/**
	 * The listener that should retrieve mouse events
	 */
	private MouseListener listener;
	
	public TransMouseListener(Component source, MouseListener listener) {
		if (source == null)
			throw new IllegalArgumentException("The argument source is null");
		if (listener== null)
			throw new IllegalArgumentException("The argument listener is null");
		this.source = source;
		this.listener = listener;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		e.setSource(source);
		listener.mouseClicked(e);
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		e.setSource(source);
		listener.mouseEntered(e);
	}

	@Override
	public void mouseExited(MouseEvent e) {
		e.setSource(source);
		listener.mouseExited(e);
	}

	@Override
	public void mousePressed(MouseEvent e) {
		e.setSource(source);
		listener.mousePressed(e);
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		e.setSource(source);
		listener.mouseReleased(e);
	}

}
